// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 import { NextPage } from 'next'; import Image from 'next/image'; import { useRouter } from 'next/router'; import { useCallback, useState } from 'react'; import { useQuery } from 'react-query'; import Ad from '../../../components/Ad'; import Footer from '../../../components/Footer'; import Layout from '../../../components/Layout'; import ProductPrice from '../../../components/ProductPrice'; import Recommendations from '../../../components/Recommendations'; import Select from '../../../components/Select'; import { CypressFields } from '../../../utils/Cypress'; import ApiGateway from '../../../gateways/Api.gateway'; import { Product } from '../../../protos/demo'; import AdProvider from '../../../providers/Ad.provider'; import { useCart } from '../../../providers/Cart.provider'; import * as S from '../../../styles/ProductDetail.styled'; import { useCurrency } from '../../../providers/Currency.provider'; const quantityOptions = new Array(10).fill(0).map((_, i) => i + 1); const ProductDetail: NextPage = () => { const { push, query } = useRouter(); const [quantity, setQuantity] = useState(1); const { addItem, cart: { items }, } = useCart(); const { selectedCurrency } = useCurrency(); const productId = query.productId as string; const { data: { name, picture, description, priceUsd = { units: 0, currencyCode: 'USD', nanos: 0 }, categories, } = {} as Product, } = useQuery( ['product', productId, 'selectedCurrency', selectedCurrency], () => ApiGateway.getProduct(productId, selectedCurrency), { enabled: !!productId, } ); const onAddItem = useCallback(async () => { await addItem({ productId, quantity, }); push('/cart'); }, [addItem, productId, quantity, push]); return ( productId)]} contextKeys={[...new Set(categories)]} > {name} {description} Quantity cart Add To Cart